//
//  LYWelcomeViewController.swift
//  Sina_Weibo2
//
//  Created by Elsevier on 16/5/16.
//  Copyright © 2016年 Yang Lu. All rights reserved.
//

import UIKit
import SnapKit

class LYWelcomeViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        prepareUI()
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        moveAnimation()
    }
    
    private func moveAnimation() {
        
        // 弹簧动画
        // usingSpringWithDamping: 弹簧的明显程度 0 - 1
        // initialSpringVelocity: 初始速度
        
        UIView.animateWithDuration(1, delay: 0.1, usingSpringWithDamping: 0.5, initialSpringVelocity: 5, options: UIViewAnimationOptions(rawValue: 0), animations: { () -> Void in
            self.iconView.snp_updateConstraints(closure: { (make) -> Void in
                make.bottom.equalTo(self.view).offset(-(UIScreen.mainScreen().bounds.height - 160))
            })
            self.view.layoutIfNeeded()
            }) { (_) -> Void in
                LYPrint(items: "d动画完成")
        }
    }
    
    private func prepareUI() {
        view.addSubview(bkgView)
        view.addSubview(iconView)
        view.addSubview(messageLabel)
        
    bkgView.snp_makeConstraints { (make) -> Void in
        make.edges.equalTo(self.view)
        }
    iconView.snp_makeConstraints { (make) -> Void in
        make.centerX.equalTo(self.view)
        make.bottom.equalTo(self.view).offset(-160)
        }
    messageLabel.snp_makeConstraints { (make) -> Void in
        make.centerX.equalTo(iconView)
        make.top.equalTo(iconView.snp_bottom).offset(16)
        }
    }
    
    
    
    // MARK: - Setter & Getter 懒加载
    ///背景
    private lazy var bkgView:UIImageView = UIImageView(image: UIImage(named: "ad_background"))
    
    ///头像
    private lazy var iconView:UIImageView = {
        let imageView = UIImageView(image: UIImage(named: "avatar_default_big"))
        
        imageView.layer.cornerRadius = 42.5
        imageView.layer.masksToBounds = true
        
        return imageView
    }()
    
    //消息label
    private lazy var messageLabel:UILabel = {
       let label = UILabel()
        
        label.text = "欢迎回来"
        label.textColor = UIColor.blackColor()
        label.font = UIFont.systemFontOfSize(15)
        label.sizeToFit()
        
        return label
    }()
    
    
}




